package app

import "fmt"

const (
	StatusOK = 0

	StatusParamError           = 401
	StatusNotFound             = 404

	StatusPanicError           = 500 // 未知错误
	StatusError                = 501 // 可控错误，不易对外暴露的错误

	//StatusExceedFrequencyLimit = 503
)

var Message = map[int]string{
	StatusOK: "OK",

	StatusParamError:           "请求参数错误",
	StatusNotFound:             "未找到该记录",

	StatusPanicError:           "服务器出现未知错误Panic，请稍后重试",
	StatusError:                "服务器出现未知错误，请稍后重试",

	//StatusExceedFrequencyLimit: "超过活动请求次数限制",

}

type Error struct {
	Code    int
	Message string
}

func (e Error) Error() string {
	m := Message[e.Code]

	if len(e.Message) > 0 {
		m = e.Message
	}
	return fmt.Sprintf("%d|%s", e.Code, m)
}
